Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(refunds): update refunds filters #4409

Merged
merged 12 commits into from
May 13, 2024
Merged

feat(refunds): update refunds filters #4409

merged 12 commits into from
May 13, 2024

Conversation

apoorvdixit88
Copy link
Contributor

@apoorvdixit88 apoorvdixit88 commented Apr 22, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

The PR:

  • Adds support for new filter_v2 api to get list of available filters for refunds quickly: connector with their corresponding label with merchant_connector_ids, currency and refund status. This api is quicker than previous one and gives static and dynamic filter. In this list of available value doesn't depend on refunds that are made (present in table). But these are static and configuration dependent.

  • Modifies existing refunds list as per filters applied (also manages pagination result etc), we can filter list by amount and merchant connector ids as well and the application of previous filters on list remains same.

  • Also changed payments filter v2 (it is not being used as of now) .

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Closes #4408

How did you test it?

To get list of filters:

curl --location 'http://localhost:8080/refunds/filter_v2' \
--header 'Content-Type: application/json' \
--header 'Cookie: token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMWZjNzgyOTUtM2JiMy00OGJjLThlZDgtNzFjMzVjMzMxYWU2IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNjk3NzE2ODcwIiwicm9sZV9pZCI6Im1lcmNoYW50X2FkbWluIiwiZXhwIjoxNjk3ODg5NjcxLCJvcmdfaWQiOiJvcmdfejQ5ZExMeTdmbllUODN5TDY3clEifQ.CJzEQ2qbhn-qUiiVBSdvCJiLvWp-5wCF9R54gth6QbQ' \
--header 'Authorization: Bearer JWT' \
--data ''

Response:

{
    "connector": {
"paypal_test": [
            {
                "connector_label": "payal_test_default",
                "merchant_connector_id": "mca_test"
            }
},
    "currency": [
        "AED",
        "ALL",
        "AMD",
        "ANG",
        "AOA",
        "ARS",
        "AUD",
        "AWG",
        "AZN",
        "BAM",
        "BBD",
        "BDT",
        "BGN",
        "BHD",
        "BIF",
        "BMD",
        "BND",
        "BOB",
        "BRL",
        "BSD",
        "BWP",
        "BYN",
        "BZD",
        "CAD",
        "CHF",
        "CLP",
        "CNY",
        "COP",
        "CRC",
        "CUP",
        "CVE",
        "CZK",
        "DJF",
        "DKK",
        "DOP",
        "DZD",
        "EGP",
        "ETB",
        "EUR",
        "FJD",
        "FKP",
        "GBP",
        "GEL",
        "GHS",
        "GIP",
        "GMD",
        "GNF",
        "GTQ",
        "GYD",
        "HKD",
        "HNL",
        "HRK",
        "HTG",
        "HUF",
        "IDR",
        "ILS",
        "INR",
        "IQD",
        "JMD",
        "JOD",
        "JPY",
        "KES",
        "KGS",
        "KHR",
        "KMF",
        "KRW",
        "KWD",
        "KYD",
        "KZT",
        "LAK",
        "LBP",
        "LKR",
        "LRD",
        "LSL",
        "LYD",
        "MAD",
        "MDL",
        "MGA",
        "MKD",
        "MMK",
        "MNT",
        "MOP",
        "MRU",
        "MUR",
        "MVR",
        "MWK",
        "MXN",
        "MYR",
        "MZN",
        "NAD",
        "NGN",
        "NIO",
        "NOK",
        "NPR",
        "NZD",
        "OMR",
        "PAB",
        "PEN",
        "PGK",
        "PHP",
        "PKR",
        "PLN",
        "PYG",
        "QAR",
        "RON",
        "RSD",
        "RUB",
        "RWF",
        "SAR",
        "SBD",
        "SCR",
        "SEK",
        "SGD",
        "SHP",
        "SLE",
        "SLL",
        "SOS",
        "SRD",
        "SSP",
        "STN",
        "SVC",
        "SZL",
        "THB",
        "TND",
        "TOP",
        "TRY",
        "TTD",
        "TWD",
        "TZS",
        "UAH",
        "UGX",
        "USD",
        "UYU",
        "UZS",
        "VES",
        "VND",
        "VUV",
        "WST",
        "XAF",
        "XCD",
        "XOF",
        "XPF",
        "YER",
        "ZAR",
        "ZMW"
    ],
    "refund_status": [
        "Failure",
        "ManualReview",
        "Pending",
        "Success",
        "TransactionFailure"
    ]
}

To filter refunds list by new parameters i.e., amount and merchant_connector_id

curl --location 'http://localhost:8080/refunds/list' \
--header 'Content-Type: application/json' \
--header 'Cookie: token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMWZjNzgyOTUtM2JiMy00OGJjLThlZDgtNzFjMzVjMzMxYWU2IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNjk3NzE2ODcwIiwicm9sZV9pZCI6Im1lcmNoYW50X2FkbWluIiwiZXhwIjoxNjk3ODg5NjcxLCJvcmdfaWQiOiJvcmdfejQ5ZExMeTdmbllUODN5TDY3clEifQ.CJzEQ2qbhn-qUiiVBSdvCJiLvWp-5wCF9R54gth6QbQ' \
--header 'Authorization: Bearer JWT' \
--data '{
    "merchant_connector_id": ["mca_test1", "mca_test_2"],
   "connector": ["paypal_test"],
    "amount_filter": {
       "start_amount": 12600,
        "end_amount": 12600
    }
    
}'

Response:

{
    "count": 1,
    "total_count": 1,
    "data": [
        {
            "refund_id": "test_YqXmZZAtH9Hr97ZVA2lo",
            "payment_id": "test_KuyhzmNelel8VKEVLHUi",
            "amount": 12600,
            "currency": "USD",
            "status": "succeeded",
            "reason": "Sample Refund",
            "metadata": null,
            "error_message": null,
            "error_code": null,
            "created_at": "2024-04-22T05:58:24.000Z",
            "updated_at": "2024-04-22T05:58:24.000Z",
            "connector": "paypal_test",
            "profile_id": "pro_itP1UHdaBjqXsFF0WoAm",
            "merchant_connector_id": "mca_test1"
        }
    ]
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible
  • I added a CHANGELOG entry if applicable

@apoorvdixit88 apoorvdixit88 added C-feature Category: Feature request or enhancement S-waiting-on-review Status: This PR has been implemented and needs to be reviewed A-refunds Area: Refund flows labels Apr 22, 2024
@apoorvdixit88 apoorvdixit88 self-assigned this Apr 22, 2024
@apoorvdixit88 apoorvdixit88 requested review from a team as code owners April 22, 2024 07:31
@apoorvdixit88 apoorvdixit88 marked this pull request as draft April 22, 2024 07:31
@apoorvdixit88 apoorvdixit88 marked this pull request as ready for review April 22, 2024 16:52
get,
path = "/refunds/filter_v2",
responses(
(status = 200, description = "List of static filters", body = RefundListMetaData),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the response body type correct?

ThisIsMani
ThisIsMani previously approved these changes Apr 24, 2024
#[derive(Clone, Debug, serde::Serialize, ToSchema)]
pub struct RefundListFilters {
/// The list of available connector filters
pub connector: HashMap<String, Vec<MerchantConnectorInfo>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will be the key in this hashmap?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention it in the doc comment.

Comment on lines 808 to 813
.for_each(|(connector_name, info)| {
connector_map
.entry(connector_name.clone())
.or_default()
.push(info);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrithikesh026
hrithikesh026 previously approved these changes May 7, 2024
ThisIsMani
ThisIsMani previously approved these changes May 13, 2024
racnan
racnan previously approved these changes May 13, 2024
Copy link
Contributor

@racnan racnan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor stuff

@@ -702,7 +702,8 @@ impl Refunds {
{
route = route
.service(web::resource("/list").route(web::post().to(refunds_list)))
.service(web::resource("/filter").route(web::post().to(refunds_filter_list)));
.service(web::resource("/filter").route(web::post().to(refunds_filter_list)))
.service(web::resource("/filter_v2").route(web::get().to(get_refunds_filters)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be named with/v2 prefix or suffix.

};

let connector_map = merchant_connector_accounts
.iter()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use into_iter() and remove as_ref() and clone().

if let Some(connector) = refund_list_details.clone().connector {
filter = filter.filter(dsl::connector.eq_any(connector));
}

if let Some(merchant_connector_id) = refund_list_details.clone().merchant_connector_id {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this work without cloning the whole struct ?

hrithikesh026
hrithikesh026 previously approved these changes May 13, 2024
racnan
racnan previously approved these changes May 13, 2024
@likhinbopanna likhinbopanna removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label May 13, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue May 13, 2024
Merged via the queue into main with commit cfab2af May 13, 2024
9 of 12 checks passed
@likhinbopanna likhinbopanna deleted the refunds-filters-v2 branch May 13, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-refunds Area: Refund flows C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

update refunds filters and list
6 participants